<%@page import="transfer.Address"%>
<%@page import="transfer.User"%>
<%@page import="controller.SessionAttribute"%>
<%@page import="transfer.Comment"%>
<%@page import="transfer.Order"%>
<%@page import="content.OrderContent"%>
<%@page import="java.util.ArrayList"%>

<div class="block-header">New delivery</div>
<div class="box">
    <table class="table" rules=all>
        <tr>
            <td>#</td>
            <td>Data</td>
            <td>Customer name</td>
            <td>Address</td>
            <td>Price</td>
            <!--<td>Comments</td>-->
        </tr>
        <%
            ArrayList orderList = OrderContent.getAllShipping((User) session.getAttribute(SessionAttribute.USER));
            for (int i = 0; i < orderList.size(); i++) {
                Order order = (Order) orderList.get(i);
        %>
        <tr>
            <td><a href="admin.jsp?content=courier&operation=view&id=<%=order.getIdOrder()%>"><%=order.getIdOrder()%></a></td>
            <td><%=order.getCreationDate()%></td>
            <%
                User customer = order.getCustomer();
                String customerName = "Anonymous customer";
                if (customer != null) {
                    customerName = customer.getFirstName() + " " + customer.getLastName();
                }
                Address address = order.getAddress();
                if (address == null) {
                    if (customer != null) {
                        address = customer.getAddress();
                    } 
                }
            %>
            <td><%= customerName%></td>
            <td><%= address%></td>
            <td><%= order.getTotalCost()%> $</td>
        </tr>
        <%
            }
        %>
    </table>
</div>